package com.itheima.lucene;

import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.Version;

import java.io.File;
import java.io.IOException;
import org.apache.lucene.document.*;

public class indexWriterTest {
    public static void main(String[] args) throws IOException {
        //创建目录对象
        Directory directory = FSDirectory.open(new File("F:\\workspace27\\lucene\\index"));
        //创建config对象
        IndexWriterConfig config = new IndexWriterConfig(Version.LATEST, new StandardAnalyzer());


        //创建索引写入核心对象
        IndexWriter indexWriter = new IndexWriter(directory, config);
        //添加文档数据
       Document doc=new Document();
        doc.add(new LongField("pid",1, Field.Store.YES));
        doc.add(new StringField("title","zhoulei",Field.Store.YES));
        doc.add(new TextField("content","周磊是个伪娘 娘们唧唧的",Field.Store.YES));
        indexWriter.addDocument(doc);
        //提交数据
        indexWriter.commit();
        //释放资源
        indexWriter.close();







    }


}
